package com.bjsxt.homework1;

public class Printer {

    private int index = 1;
    public synchronized void printNumber(int n) {

        if (index % 2 == 0) {
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.print(n);
        System.out.print(n + 1);

        index++;

        this.notify();
    }

    public synchronized void printLetter(char c) {

        if (index % 2 == 1) {
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.print(c);

        index++;

        this.notify();
    }
}
